package ar.com.angrymachine.hunter.activities;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Activity;
import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.HunterResourceManager;

public class TrainerActivity extends Activity
{
    private double goldTrainRatio = 2.0; // 2 gold per train point
    private double trainPointBonus = 0.005; // how much to increase each activity per train point
    
    public static final int TYPE_FIGHTING = 1;
    public static final int TYPE_DISARM = 2;
    public static final int TYPE_EXPLORATION = 3;
    public static final int TYPE_MAGIC = 4;
    
    private int type;
    
    public TrainerActivity(int type)
    {
    	this.type = type;
    }

	public String getDescription()
	{
		switch(type)
		{
			case TYPE_DISARM:
				return Locale.TRAINER_DISARM;
			case TYPE_FIGHTING:
			default:
				return Locale.TRAINER_FIGHTING;
			case TYPE_EXPLORATION:
				return Locale.TRAINER_EXPLORATION;
			case TYPE_MAGIC:
				return Locale.TRAINER_MAGIC;
		}
	}

	public String getActionText()
	{
		if(isRunning())
		{
			return Locale.TRAINING;
		}
		else
		{
			return Locale.TRAIN;
		}
	}

	public void update(int delta, boolean action, boolean timeIsRunning)
	{
        if(timeIsRunning)
        {
            if(action)
            {
            	// increase training, decrease gold
            	int goldToTake = (int) goldTrainRatio;
            	if(Game.current.player.gold >= goldToTake)
            	{
            		Game.current.player.gold -= goldToTake;
            		switch(type)
            		{
            			case TYPE_DISARM:
            				Game.current.player.naturalDisarmSkill += trainPointBonus;
            				break;
            			case TYPE_FIGHTING:
            				Game.current.player.naturalFightingSkill += trainPointBonus;
            				break;
            			case TYPE_EXPLORATION:
            				Game.current.player.naturalExplorationSkill += trainPointBonus;
            				break;
            			case TYPE_MAGIC:
            				Game.current.player.naturalMagicSkill += trainPointBonus;
            				break;
            		}
            	}
            }
        }
	}

	public boolean isCompleted()
	{
		return false;
	}

	public void paint(Graphics g, Rectangle activityArea)
	{
		Image icon;
		switch(type)
		{
			case TYPE_DISARM:
				icon = HunterResourceManager.getImage("town-trainer-disarm.png");
				break;
			case TYPE_EXPLORATION:
				icon = HunterResourceManager.getImage("town-trainer-exploration.png");
				break;
			case TYPE_MAGIC:
				icon = HunterResourceManager.getImage("town-trainer-magic.png");
				break;
			case TYPE_FIGHTING:
				default:
				icon = HunterResourceManager.getImage("town-trainer-fighting.png");
				break;
		}
		GraphicStyles.paintDefaultActivity(g, this, activityArea, icon);
	}
}
